###################################
###### Main replication file ######
###################################

rm(list = ls())

# to load packages, install pacman if not already installed
# also, install starpolishr from github if necessary

if (!require("pacman")) install.packages("pacman")
if (!require("starpolishr")) devtools::install_github("ChandlerLutz/starpolishr")

# function to reproduce table and plot output
reproduce <- function () {
    # verify (or create) necessary file structure for output
    if(!file.exists("./figs")) dir.create("./figs")
    if(!file.exists("./tables")) dir.create("./tables")
    
    # analysis for study 1
    source("./scripts/analyze_psych_s1.R") 
    
    # analysis for study 2
    source("./scripts/analyze_psych_s2.R") # generate predictions and plots

    # to replicate tables from main text
    source("./scripts/combined_psych_models.R")

    # to replicate plots from main text
    source("./scripts/psych_plots.R")

    # analysis using multilevel models
    source("./scripts/multilevel_models.R")

    # to replicate tables for multilevel model results
    source("./scripts/format_multilevel_tables.R")
}

reproduce()

